﻿using Microsoft.EntityFrameworkCore;
using Abp.Zero.EntityFrameworkCore;
using Sunlit.House.Authorization.Roles;
using Sunlit.House.Authorization.Users;
using Sunlit.House.MultiTenancy;
using Sunlit.House.Articles;
using Sunlit.House.Regions;
using Sunlit.House.Books;
using Sunlit.House.Floors;
using Sunlit.House.Buy;
using Sunlit.House.Seconds;

namespace Sunlit.House.EntityFrameworkCore
{
    public class HouseDbContext : AbpZeroDbContext<Tenant, Role, User, HouseDbContext>
    {
        /* Define a DbSet for each entity of the application */
        /// <summary>
        /// 地区表
        /// </summary>
        public DbSet<Region> Regions { get; set; }
        /// <summary>
        /// 新闻类别
        /// </summary>
        public DbSet<NewsCategory> NewsCategories { get; set; }
        /// <summary>
        /// 新闻
        /// </summary>
        public DbSet<News> News { get; set; }
        /// <summary>
        /// 留言信息
        /// </summary>
        public DbSet<Book> Books { get; set; }
        /// <summary>
        /// 楼盘
        /// </summary>
        public DbSet<Floor> Floors { get; set; }
        /// <summary>
        /// 楼盘图片
        /// </summary>
        public DbSet<FloorImage> FloorImages { get; set; }
        /// <summary>
        /// 小区
        /// </summary>
        public DbSet<Village> Villages { get; set; }
        /// <summary>
        /// 二手房
        /// </summary>
        public DbSet<SecondHand> SecondHands { get; set; }
        /// <summary>
        /// 二手房图片
        /// </summary>
        public DbSet<SecondHandImage> SecondHandImages { get; set; }
        /// <summary>
        /// 团购设置类
        /// </summary>
        public DbSet<GroupBuyType> GroupBuyTypes { get; set; }
        /// <summary>
        /// 团购
        /// </summary>
        public DbSet<GroupBuy> GroupBuys { get; set; }
        /// <summary>
        /// 团购参与信息
        /// </summary>
        public DbSet<GroupItem> GroupItems { get; set; }


        public HouseDbContext(DbContextOptions<HouseDbContext> options)
            : base(options)
        {

        }
        protected override void OnModelCreating(ModelBuilder modelBuilder)
        {
            base.OnModelCreating(modelBuilder);
            // 地区自关联关系
            modelBuilder.Entity<Region>(r =>
            {
                r.HasMany(a => a.ChildRegions).WithOne(a => a.ParentRegion).HasForeignKey(a => a.ParentId);
            });
        }
    }
}
